/**
 * @file show_char.c
 * @author your name (you@domain.com)
 * @brief 以取模打点方式在LCD上显示字符
 * @version 0.1
 * @date 2023-06-28
 * 
 * @copyright Copyright (c) 2023
 * 
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>

#define FB_DEVICE "/dev/fb0" /* LCD设备节点 */

static int width; /* LCD 宽度 */
static int height; /* LCD 高度 */
static unsigned short *screen_base = NULL; /* LCD显存基地址  */

static unsigned char ch_char1[86][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0xFF,0xFF,0xFF,0x01},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0x00,0xFC,0x07,0xC0,0x7F,0x00,0x00,0x00},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"正",0*/
};

static unsigned char ch_char2[86][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0x0F},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0x01,0x00,0x00,0xC0,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00},
{0x00,0x01,0x00,0x00,0xC0,0x00,0x7C,0x00},
{0x00,0x0F,0x00,0x03,0xF8,0x00,0x7F,0x00},
{0x80,0x3F,0xF0,0x03,0xFF,0x81,0xFF,0x00},
{0x80,0xFF,0xFC,0x03,0xFE,0x81,0xFF,0x00},
{0xC0,0x7F,0xFC,0x07,0xFE,0x03,0xFF,0x01},
{0xC0,0x7F,0xF8,0x07,0xFC,0x03,0xFF,0x01},
{0xE0,0x3F,0xF8,0x0F,0xFC,0x07,0xFE,0x01},
{0xE0,0x3F,0xF0,0x0F,0xFC,0x07,0xFE,0x03},
{0xF0,0x1F,0xF0,0x0F,0xF8,0x07,0xFE,0x03},
{0xF0,0x1F,0xF0,0x1F,0xF8,0x0F,0xFC,0x07},
{0xF8,0x0F,0xE0,0x1F,0xF8,0x0F,0xFC,0x07},
{0xF8,0x0F,0xE0,0x1F,0xF0,0x0F,0xF8,0x0F},
{0xFC,0x07,0xE0,0x3F,0xF0,0x1F,0xF8,0x0F},
{0xFC,0x07,0xE0,0x3F,0xF0,0x1F,0xF0,0x1F},
{0xFC,0x03,0xC0,0x0F,0xE0,0x03,0xF0,0x07},
{0xF0,0x03,0xC0,0x00,0x60,0x00,0xE0,0x01},
{0xE0,0x01,0x00,0x00,0x00,0x00,0x20,0x00},
{0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"点",1*/
};

static unsigned char ch_char3[86][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x80,0x7F,0x00,0x80,0xFF,0x00,0x00,0x00},
{0x80,0x7F,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x80,0x7F,0x00,0xC0,0x7F,0x00,0x00,0x00},
{0x80,0x7F,0x00,0xC0,0x3F,0x00,0x00,0x00},
{0x80,0x7F,0x00,0xE0,0x3F,0x00,0x00,0x00},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0x80,0x7F,0xF8,0x07,0x00,0x00,0xFE,0x01},
{0xC0,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0xC0,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0xC0,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0xC0,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0xC0,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0xC0,0x7F,0xF8,0xFF,0xFF,0xFF,0xFF,0x01},
{0xC0,0x3F,0x00,0x00,0xFC,0x07,0x06,0x00},
{0xC0,0x3F,0x80,0x00,0xFC,0x07,0x07,0x00},
{0xC0,0x3F,0x80,0x03,0xFC,0x87,0x0F,0x00},
{0xE0,0x3F,0xC0,0x07,0xFC,0xE7,0x1F,0x00},
{0xE0,0x3F,0xE0,0x1F,0xFC,0xF7,0x3F,0x00},
{0xE0,0x3F,0xF0,0x3F,0xFC,0xE7,0x7F,0x00},
{0xE0,0x1F,0xF0,0x3F,0xFC,0xE7,0xFF,0x00},
{0xF0,0x1F,0xF8,0x1F,0xFC,0xC7,0xFF,0x00},
{0xF0,0x1F,0xFC,0x0F,0xFC,0x87,0xFF,0x01},
{0xF0,0x1F,0xFE,0x0F,0xFC,0x07,0xFF,0x03},
{0xF0,0x1F,0xFF,0x07,0xFC,0x07,0xFF,0x07},
{0xF8,0x8F,0xFF,0x03,0xFC,0x07,0xFE,0x0F},
{0xF8,0x8F,0xFF,0x01,0xFE,0x07,0xFC,0x0F},
{0xFC,0xCF,0xFF,0xFF,0xFF,0x07,0xF8,0x1F},
{0xFC,0xE7,0xFF,0xFE,0xFF,0x07,0xF8,0x0F},
{0xFE,0xC7,0x7F,0xFE,0xFF,0x03,0xF0,0x07},
{0xFE,0x83,0x3F,0xFC,0xFF,0x03,0xE0,0x03},
{0xF8,0x03,0x1F,0xFC,0xFF,0x03,0xE0,0x00},
{0xF0,0x03,0x0E,0xFC,0xFF,0x01,0x40,0x00},
{0xE0,0x01,0x04,0xFC,0xFF,0x00,0x00,0x00},
{0xC0,0x00,0x00,0xFC,0x3F,0x00,0x00,0x00},
{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"原",2*/
};

static unsigned char ch_char4[86][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00},
{0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0x00},
{0x00,0x00,0x00,0x00,0x00,0xFF,0x3F,0x00},
{0x00,0x00,0x00,0x00,0xC0,0xFF,0x1F,0x00},
{0x00,0x00,0x00,0x00,0xF0,0xFF,0x07,0x00},
{0x00,0x00,0x00,0x00,0xF8,0xFF,0x03,0x00},
{0x00,0x00,0x00,0x00,0xFE,0xFF,0x00,0x00},
{0x00,0x00,0x00,0x80,0xFF,0x7F,0x00,0x00},
{0x00,0x00,0x00,0xC0,0xFF,0x1F,0x00,0x00},
{0x00,0x00,0x00,0xF0,0xFF,0x07,0x00,0x00},
{0x00,0x00,0x00,0xF8,0xFF,0x03,0x00,0x00},
{0x00,0x00,0x00,0xF8,0xFF,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x7F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xF8,0x0F,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFC,0x0F,0x00,0x00,0x00},
{0x00,0x10,0x00,0xFE,0x0F,0x00,0x00,0x00},
{0x00,0xF0,0xFF,0xFF,0x0F,0x00,0x00,0x00},
{0x00,0xF0,0xFF,0xFF,0x0F,0x00,0x00,0x00},
{0x00,0xE0,0xFF,0xFF,0x0F,0x00,0x00,0x00},
{0x00,0xE0,0xFF,0xFF,0x07,0x00,0x00,0x00},
{0x00,0xE0,0xFF,0xFF,0x07,0x00,0x00,0x00},
{0x00,0xE0,0xFF,0xFF,0x03,0x00,0x00,0x00},
{0x00,0xC0,0xFF,0xFF,0x01,0x00,0x00,0x00},
{0x00,0xC0,0xFF,0xFF,0x00,0x00,0x00,0x00},
{0x00,0xC0,0xFF,0x3F,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"子",3*/
};

#define ARGB8888_TO_RGB565(color)   ({ \
            unsigned int temp = (color); \
            ((temp & 0xF80000UL) >> 8) | \
            ((temp & 0xFC00UL) >> 5) | \
            ((temp & 0xF8UL) >> 3); \
            })

/**
 * @brief 在LCD屏幕指定位置(x,y)处画字符，
 * 
 * @param x 
 * @param y 
 * @param ch 字符对应的字模数组
 * @param w 字符的宽度
 * @param h 字符的高度
 * @param color 字符的颜色
 */
static void lcd_draw_character(unsigned int x, unsigned int y,
                const unsigned char *ch, unsigned int w,
                unsigned int h, unsigned int color)
{
    unsigned short rgb565_color = ARGB8888_TO_RGB565(color);
    unsigned long temp;
    unsigned int end_x, end_y;
    int columns;
    int j;
    /* 计算出二维数组有多少列，参数w表示的是字符的宽度，1个宽度表示的是一个bit位
       不是一个字节，注意，如果宽度不是byte单位的整数倍，通常会补零 */
    columns = w / 8; /* 1byte = 8bit */
    if (0 != w % 8) { columns++; }
    /* 对参数进行限定 */
    if (w < 1 || h < 1) { return; }
    if (x >= width || y >= height) { return; }
    /* 计算出结束坐标位置 */
    end_x = x + w - 1;
    end_y = y + h - 1;
    /* 对结束坐标位置进行限定 */
    if (end_x >= width) { end_x = width - 1; }
    if (end_y >= height) { end_y = height - 1; }
    /* 计算有效宽度 */
    h = end_y - y + 1;
    w = end_x - x + 1;
    /* 打点 */
    temp = y * width + x; /* 定位到起点 */
    for (y = 0; y < h; y++, temp += width) {
        for (x = 0, j = 0; x < w; ) {
            if (*(ch + y * columns + j) & (0x1 << (x % 8))) {
                screen_base[temp + x] = rgb565_color;
            }
            if (0 == x%8) { j++; }
        }
    }
}

int main(int argc, char const *argv[])
{
    struct fb_var_screeninfo fb_var;
    struct fb_fix_screeninfo fb_fix;
    unsigned long screen_size;
    int fd;
    
    /* 打开 framebuffer设备 */
    fd = open(FB_DEVICE, O_RDWR);
    if (fd < 0) { 
        fprintf(stderr, "open error: %s:%s\n", FB_DEVICE, strerror(errno));
        exit(EXIT_FAILURE);
    }
    /* 获取模framebuffer设备信息 */
    ioctl(fd, FBIOGET_FSCREENINFO, &fb_fix);
    ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
    screen_size = fb_fix.line_length * fb_var.yres;
    width = fb_var.xres;
    height = fb_var.yres;
    /* 内存映射 */
    screen_base = mmap(NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED,
                    fd, 0);
    if (MAP_FAILED == (void*)screen_base) {
        perror("mmap error");
        close(fd);
        exit(EXIT_FAILURE);
    }
    /* LCD背景刷白 */
    memset(screen_base, 0xFF, screen_size);
    /* 显示字符 */
    int x = width * 0.5 - 128;
    int y = height * 0.5 - 43;
    lcd_draw_character(x, y, (unsigned char*)ch_char1, 64, 86, 0xFF00FF);
    lcd_draw_character(x+64, y, (unsigned char*)ch_char2, 64, 86, 0xFF00FF);
    lcd_draw_character(x+128, y, (unsigned char*)ch_char3, 64, 86, 0xFF00FF);
    lcd_draw_character(x+192, y, (unsigned char*)ch_char4, 64, 86, 0xFF00FF);
    /* 退出程序 */
    munmap(screen_base, screen_size);
    close(fd);
    return 0;
}
